<template>
  <!-- 大客户线索管理->线索分配 -->
  <div>
    <!-- 搜索 -->
     <TopFilter  :list="topFilterInit" 
     :cols="4"  
     :collapse="collapse"
     labelWidth="90"  
     @filterChange="changeHandle" ></TopFilter>
     <!-- table -->
     <!-- //multiple -->
    <FilterTable   ref="listModal" :columns="columns" :selectionType="'multiple'"   :fetchapi="fetchApi" :params="fetchParams" 
      :datakey="'records'"
      :onRowSelectChange="selectChange"
      columnsRef='customerManage_clue_pushClue_distributionMadal_01'
      :onColumnsChange="columns => this.columns = columns">
   </FilterTable>
    <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="saveDialog" type="primary">分 配</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getManagerSelectList } from '@/api/cms-api/customerManage/clue/areaBossOperation';//大客户区域经理选择
import { oemAssignClub } from '@/api/cms-api/customerManage/clue/createClue';//大客户线索管理
import { Notification } from 'element-ui';
export default {
  mixins: [dictionary],
  props:{
    value:{
      type:Array,
      default:function(){
        return [];
      }
    }
  },
  data() {
    return {
      visible:false,
      visibleDrawer:false,
      collapse:false,
      infoId:null,
      topFilterInit:this.topFilterInitFun(),
      flterValue:{},  //参数
      columns:this.creatHeader(),
      fetchParams:null, //ipa 接口
      fetchApi:getManagerSelectList,
      selectedRows:[]
      // clueList:[]
    };
  },
  methods: {
      // init(clue){
      //   this.clueList = clue;
      // },
      //搜索数据
      topFilterInitFun(){
        return [
            { type: 'SELECT',   label: '大客户事业部', fieldName: 'majorManagerId', placeholder: '请输入',initialValue: '',itemList:this.createDictList('2566')  },
            { type: 'INPUT',  label: '员工编号',  fieldName: 'employeeNo',  placeholder: '请选择', initialValue: "" },
            { type: 'INPUT',  label: '员工名称', fieldName: 'employeeName',   placeholder: '请选择', initialValue: "" }
        ]
      },
      //选中
    selectChange(rows) {
      this.selectedRows = rows;
    },
      //搜索获取数据
      changeHandle(val){
          this.fetchParams=Object.assign({},val);
          console.log(val)
      },
      //table表头和数据源
      creatHeader(){
         return [
         {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
         },
        { title: '员工编号',  dataIndex: 'employeeNo', sorter: true},
        { title: '员工姓名',  dataIndex: 'employeeName', sorter: true},
        { title: '大客户事业部',  dataIndex: 'majorManagerId', sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.majorManagerId, '2566')}</span>;
          }
         },
        { title: '职位',   dataIndex: 'position', sorter: true},
        { title: '手机',    dataIndex: 'phone',  sorter: true},
        { title: '邮箱',  dataIndex: 'eMail',   sorter: true}
        ]
      },
        //保存
    saveDialog(){
      this.$confirm('确认分配', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(this.assignClue).catch(() => {
            // this.$notify.info({title: '提示信息',message:'已取消删除'});
          });
    },
    async assignClue(){
      if(this.selectedRows==null || this.selectedRows.length<1){
        Notification.warning({
            title: `提示信息`,
            message: `请选择区域经理！`
          });
         return;
      }
      let managerIds = '';
       
     
       for (let  i = 0 ; i < this.selectedRows.length; i++) {
      
            managerIds  = this.selectedRows[i].userId+ ',' + managerIds ;
             
          
       }
    //  this.selectedRows[0].userId;
      let fclueList = [];
      this.value.forEach(element => {
        let clueObj = {};
        clueObj.clueId = element.clueId;
        fclueList.push(clueObj);
      });
     
         
      oemAssignClub(managerIds,fclueList).then(this.closeWithData);
    },
    async closeWithData(res){
        if(res.resultCode=='200'){
           Notification.success({
            title: `提示信息`,
            message: `线索分配成功！`
          });
            this.$emit('close', {visible:false,type:"refresh"});
        }
    },
    //取消操作
    closeDialog(){
      this.$emit('close', {visible:false});
    }
  }
};
</script>

<style lang="less" scoped>
</style>
